layui.define(["form", "layer", "admin"], function (exports) {
    var form = layui.form,
        layer = layui.layer,
        admin = layui.admin;

    form.on("submit(system-edit-user-password-save)", function (data) {
        var newPassword = data.field.newPassword;
        var confirmPassword = data.field.confirmPassword;
        if (newPassword !== confirmPassword) {
            layer.msg("确认密码不一致", {icon: 5, time: 1500});
            return;
        }

        layer.confirm("确定要修改吗？", function (index) {
            layer.close(index);
            admin.req({
                url: "/system/user/updateUserPassword",
                data: data.field,
                beforeSend: function () {
                    layer.load(2, {time: 100 * 1000});
                },
                complete: function () {
                    layer.closeAll('loading');
                },
                done: function () {
                    layer.alert('密码修改成功,请重新登录', {closeBtn: 0}, function (index) {
                        layer.close(index);
                        admin.exit();
                    });
                }
            });
        });

        return false;
    });

    exports("editUserPassword", {});
});